package com.yxp.offer;

import java.util.ArrayList;
import java.util.List;

/**
 * @Auther : yxpweb
 * @Date : 2021/8/21 8:37
 * @Description: 动态规划 剑指 Offer 47. 礼物的最大价值
 */
public class Problem47 {

    public static void main(String[] args) {
        int[][] grid = new int[][]{{1, 3, 1}, {1, 5, 1}, {4, 2, 1}};
        Problem47 problem47 = new Problem47();
        System.out.println(problem47.maxValue(grid));
    }

    public int maxValue(int[][] grid) {
        int m = grid.length, n = grid[0].length;
        int[] dp = new int[n + 1];
        for (int i = 1; i <= m; i++) {
            for (int j = 1; j <= n; j++) {
                dp[j] = Math.max(dp[j], dp[j - 1]) + grid[i - 1][j - 1];
            }
        }
        List<Integer> list = new ArrayList<>();
        for (int i = 0; i < dp.length; i++) {
            list.add(dp[i]);
        }
        System.out.println(list);
        return dp[n];
    }
}
